﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
//using System.Configuration.ConfigurationManager;
namespace AtlasGis
{
    public class ketnoi
    {
        SqlConnection con = new SqlConnection();
        string ketnoi1 = ConfigurationManager.ConnectionStrings["project"].ConnectionString;

        public ketnoi()
          {
              con.ConnectionString = ketnoi1;
              if (con.State == ConnectionState.Closed)
                  con.Open();
          }

        public DataTable LayDuLieu(string sql)
        {
            SqlCommand command = new SqlCommand(sql, con);
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return dt;
        }


        public DataTable LayDuLieu(string sql, string[] name, object[] value, int Nparameter)
           { 
          SqlCommand command = new SqlCommand(sql,con);
          for(int i=0;i<Nparameter;i++)
              {
              command.Parameters.AddWithValue(name[i], value[i]);
              }
          SqlDataAdapter adapter = new SqlDataAdapter(command);
          DataTable dt= new DataTable();
          adapter.Fill(dt);
          return dt;
          }

        public int update(string sql)
        {
            SqlCommand command = new SqlCommand(sql, con);
            return command.ExecuteNonQuery();
        }

        public int update(string sql, string[] name, object[] value, int Nparameter)
        {
            SqlCommand command = new SqlCommand(sql, con);
            for (int i = 0; i < Nparameter; i++)
            {

                command.Parameters.AddWithValue(name[i], value[i]);
            }
            return command.ExecuteNonQuery();
               
        }
     
    }
}
